<template>
	<view>
		<text class="timer">{{formattedTime}}</text>
	</view>
</template>
<script>
	export default {
		props: {
			startTime: {
				type: String,
				required: true,
			},
		},
		data() {
			return{
				formattedTime: '00:00:00',
				timer: null,
			}
		},
		
		methods: {
			startTimer() {
				
				this.timer = setInterval(() => {
					const currentTime = new Date();
					
					const elapsedMilliseconds = currentTime - new Date(this.startTime);
					
					// 计算经过的小时、分钟和秒
					const seconds = Math.floor((elapsedMilliseconds / 1000) % 60);
					const minutes = Math.floor((elapsedMilliseconds / (1000 * 60)) % 60);
					const hours = Math.floor((elapsedMilliseconds / (1000 * 60 * 60)));

					// 格式化为两位数
					const formattedTime = String(hours).padStart(2, '0') + ':' +
						String(minutes).padStart(2, '0') + ':' +
						String(seconds).padStart(2, '0');

					this.formattedTime = formattedTime
				}, 1000);
			},
		},
		
	}
</script>
<style>
</style>